#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>



int main() {
    int tz[6][6] = { 0 }, i, j, c, ds, cs;
    for (i = 0; i < 6; i++) {
        scanf("%d", &ds);
        tz[i][ds-1] = 1;
    }
    scanf("%d", &cs);
    for (i = 0; i < 6; i++) {
        for (j = 5; j > 6 - cs; j--) {
            c = j;
            while (tz[i][c] != 0)
                c--;
            tz[i][c] = 1;

        }
    }
    i = 5;
    while (tz[0][i] != 0)
        i--;
    printf("%d", i+1);
    for (j = 1; j < 6; j++) {
        i = 5;
        while (tz[j][i] != 0)
            i--;
        printf(" %d", i+1);
    }

    return 0;
}







/*int temp_length(int x) {
    int count = 0;
    while (x > 0) {
        x /= 10;
        count++;
    };
    return count;
}

int main() {
    int sz[1001] = { 0 };
    int cs, i, temp, j, m = 0;
        scanf("%d %d %d", &sz[0], &sz[1], &cs);

    for (j = 2, i = 0; j < cs; j++,i++) {
        temp = sz[i] * sz[i+1];
        do{
            m = temp_length(temp) - 1;
            sz[j++] = (int)(temp / pow(10, m--));
        } while (m > 0);
        
        if(temp_length(temp)>1)
            sz[j++] = temp % 10;
        j--;
    }
    printf("%d %d", sz[0],sz[1]);
    for (i = 2; i < cs; i++)
        printf(" %d", sz[i]);


    return 0;
}





int main() {
    int f[1001] = { 0 };
    int n, z, i, j, cs, bh, flag = 1;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &cs);

        for (j = 1; j < cs; j++) {
            scanf("%d", &bh);
            f[bh]++;
        }

    }

    for (i = 1; i < 1002; i++) {
        if (f[i] >= f[flag])
            flag = i;
    }
    printf("%d %d", flag, f[flag]);

    return 0;
}*/